(defun hooks/paredit-mode ()
  "Enable the Paredit mode."
  (interactive)
  (paredit-mode 1))

;;;;Compilation hooks

(defun hooks/c-compilation (cc cflags)
  "C compilation command. If there is no makefile, it defaults to CC CFLAGS -o <file> <file>.c"
  (cond
   ((or (file-exists-p "makefile")
	(file-exists-p "Makefile"))
    (setq-local compile-command "make -B"))
   ((file-exists-p "build.sh")
    (setq-local compile-command "./build.sh"))
   (t (let ((file-no-ext (shell-quote-argument (file-name-base buffer-file-name)))
	    (file-name (shell-quote-argument (file-relative-name buffer-file-name))))
	(setq-local compile-command
		    (concat cc " " cflags " -o "
			    file-no-ext " "
			    file-name))))))

(defun hooks/java-compilation ()
  "Java compilation command. src and bin directories are necessary."
  (letrec ((project-classpath (shell-quote-argument (file-name-directory buffer-file-name)))
	   (bin-dir (shell-quote-argument (concat (file-name-parent-directory project-classpath) "bin/")))
	   (current-file (shell-quote-argument buffer-file-name)))
    (setq-local compile-command
		(concat "javac -classpath " project-classpath " -d " bin-dir " " current-file))))

(defun hooks/nroff-compilation ()
  "Nroff compilation command."
  (let ((extension (shell-quote-argument (file-name-extension buffer-file-name)))
	(fname (shell-quote-argument (file-relative-name buffer-file-name)))
	(file-as-pdf (shell-quote-argument
		      (concat (file-name-base buffer-file-name) ".pdf"))))
    (setq-local compile-command
		(concat "preconv " fname " | refer | preconv | groff -" extension " -e -p -U -D utf8 -Tpdf - > " file-as-pdf))))

;;;;Display information
(defun hooks/display-startup-time ()
  "Display the time Emacs takes to start up."
  (message "Emacs took %s to start up with %d garbage collections."
	   (emacs-init-time "%.2f seconds")
	   gcs-done))
